cmake_minimum_required(VERSION 2.8)

SET(PRJ_NAME 				https-server)

SET(PRJ_ROOTDIR				${CMAKE_CURRENT_SOURCE_DIR} )

PROJECT(${PRJ_NAME} 		C CXX)

MESSAGE(STATUS "Building https server.")
MESSAGE(STATUS "$ openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out cert.pem")

INCLUDE_DIRECTORIES( 
	"${PRJ_ROOTDIR}"
	"${PRJ_ROOTDIR}/Library"
	"${PRJ_ROOTDIR}/Library/https"
	"${PRJ_ROOTDIR}/Library/mysql/include"				#mysql-connector
	"${PRJ_ROOTDIR}/Library/stpool_src"					#libstpool
	"${PRJ_ROOTDIR}/Library/stpool_src/msglog" 
	"${PRJ_ROOTDIR}/Library/stpool_src/os" 
	"${PRJ_ROOTDIR}/Library/stpool_src/factory" 
	"${PRJ_ROOTDIR}/Library/stpool_src/pool" 
	"${PRJ_ROOTDIR}/Library/stpool_src/pool/core" 
	"${PRJ_ROOTDIR}/Library/stpool_src/pool/com" 
	"${PRJ_ROOTDIR}/Library/stpool_src/pool/gp" 
	"${PRJ_ROOTDIR}/Library/stpool_src/pool/rt"

	"/usr/include/glib-2.0"
	"/usr/lib64/glib-2.0/include"
)

LINK_DIRECTORIES(
	"${PRJ_ROOTDIR}/build"								#libstpool
	"${PRJ_ROOTDIR}/Library/mysql/lib"					#mysql-connector
	"/usr/lib64"										#glib-2.0
)
	
	SET(cflags	-std=gnu99 )
	SET(cflags_stpool  -DNDEBUG -D_GNU_SOURCE -DOS_W_64 -DHAS_CLOCK_GETTIME )
	ADD_DEFINITIONS(${cflags} ${cflags_stpool})

	SET(SRCLIST_msglog 
		${PRJ_ROOTDIR}/Library/stpool_src/msglog/msglog.c
	)

	SET(SRCLIST_stpool
		${PRJ_ROOTDIR}/Library/stpool_src/os/ospx.c 
		${PRJ_ROOTDIR}/Library/stpool_src/os/ospx_error.c 
		${PRJ_ROOTDIR}/Library/stpool_src/pool/core/timer.c 
		${PRJ_ROOTDIR}/Library/stpool_src/pool/core/sm_cache.c 
		${PRJ_ROOTDIR}/Library/stpool_src/pool/core/objpool.c 
		${PRJ_ROOTDIR}/Library/stpool_src/pool/core/cpool_core.c 
		${PRJ_ROOTDIR}/Library/stpool_src/pool/core/cpool_core_gc.c 
		${PRJ_ROOTDIR}/Library/stpool_src/factory/cpool_factory.c 
		${PRJ_ROOTDIR}/Library/stpool_src/pool/com/cpool_wait.c 
		${PRJ_ROOTDIR}/Library/stpool_src/pool/com/cpool_com_method.c 
		${PRJ_ROOTDIR}/Library/stpool_src/pool/rt/cpool_rt_factory.c 
		${PRJ_ROOTDIR}/Library/stpool_src/pool/rt/cpool_rt_core_method.c 
		${PRJ_ROOTDIR}/Library/stpool_src/pool/rt/cpool_rt_method.c 
		${PRJ_ROOTDIR}/Library/stpool_src/pool/rt/cpool_rt_internal.c 
		${PRJ_ROOTDIR}/Library/stpool_src/pool/rt/cpool_rt_scheduler_dump.c 
		${PRJ_ROOTDIR}/Library/stpool_src/pool/gp/cpool_gp_factory.c 
		${PRJ_ROOTDIR}/Library/stpool_src/pool/gp/cpool_gp_core_method.c 
		${PRJ_ROOTDIR}/Library/stpool_src/pool/gp/cpool_gp_method.c 
		${PRJ_ROOTDIR}/Library/stpool_src/pool/gp/cpool_gp_advance_method.c 
		${PRJ_ROOTDIR}/Library/stpool_src/pool/gp/cpool_gp_internal.c 
		${PRJ_ROOTDIR}/Library/stpool_src/pool/gp/cpool_gp_entry.c 
		${PRJ_ROOTDIR}/Library/stpool_src/pool/gp/cpool_gp_wait.c 
		${PRJ_ROOTDIR}/Library/stpool_src/stpool.c 
		${PRJ_ROOTDIR}/Library/stpool_src/stpool_group.c 
	)
	
	#ADD_LIBRARY( msglog STATIC ${SRCLIST_msglog} )	
	#ADD_LIBRARY( stpool STATIC ${SRCLIST_stpool} )
	#set_property(TARGET stpool PROPERTY IMPORTED_LOCATION "${PRJ_ROOTDIR}/build/libstpool.a")
	#set_property(TARGET msglog PROPERTY IMPORTED_LOCATION "${PRJ_ROOTDIR}/build/libmsglog.a")

	SET(SRCLIST_https_server
		${PRJ_ROOTDIR}/Library/https/HttpsServer.c
		${PRJ_ROOTDIR}/Library/https/MD5.c
		${PRJ_ROOTDIR}/Library/https/ReadConfFile.c
		${PRJ_ROOTDIR}/Library//thr.c
		${PRJ_ROOTDIR}/Library/cJSON.c
		${PRJ_ROOTDIR}/https_service.c
		${PRJ_ROOTDIR}/db_auth_mgmt.c
		${PRJ_ROOTDIR}/db_query.c
		${PRJ_ROOTDIR}/AGENCY.c
		${PRJ_ROOTDIR}/main.c
	)

	ADD_EXECUTABLE(https-server  
	${SRCLIST_msglog}
	${SRCLIST_stpool}
	${SRCLIST_https_server} )

	TARGET_LINK_LIBRARIES(https-server  
	#-ldl 
	-lstdc++ 
	#-lm
	-lglib-2.0 
	#-lrt 
	-lpthread 
	-lssl 
	-lcrypto 
	#-lz
	#libstpool.a libmsglog.a
	libmysqlclient.a
	)
